var docTimer_urlBarListener = {	
	QueryInterface: function(aIID){
		if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
       	    aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
       		aIID.equals(Components.interfaces.nsISupports))
     	return this;
   		throw Components.results.NS_NOINTERFACE;
  	},
  	onLocationChange: function(aProgress, aRequest, aURI){
    	docTimer.processNewURL(aURI);
  	},
	onStateChange: function() {},
	onProgressChange: function() {},
	onStatusChange: function() {},
	onSecurityChange: function() {},
	onLinkIconAvailable: function() {}
};

var docTimer = {
	currentURL: null,
	time: null,
  
	init: function() {
    	// Listen for location change
    	gBrowser.addProgressListener(docTimer_urlBarListener,
       		Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);	
  	},
  
	uninit: function() {
		gBrowser.removeProgressListener(docTimer_urlBarListener);
	},

  	processNewURL: function(aURI) {
    	if (aURI.spec == this.currentURL) return;
    	var d = new Date();
    	var t = d.getTime();
    	if(this.time != null){
    		alert(this.currentURL+" consulted during "+(t-this.time)+" milliseconds");
    	}
    	this.currentURL = aURI.spec;
    	this.time = t;
  	}

};

window.addEventListener("load", function() {docTimer.init()}, false);
window.addEventListener("unload", function() {docTimer.uninit()}, false);